package cn.iocoder.yudao.module.system.controller.app.article;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.article.vo.SystemArticleRespVO;
import cn.iocoder.yudao.module.system.service.article.SystemArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 弹窗文章")
@RestController
@RequestMapping("/system/article")
@Validated
public class AppSystemArticleController {

    @Resource
    private SystemArticleService articleService;

    @GetMapping("/list")
    @Operation(summary = "获得弹窗文章")
    @PermitAll
    public CommonResult<List<SystemArticleRespVO>> getArticlePage(@RequestParam Integer type) {
        return success(BeanUtils.toBean(articleService.getArticleListByType(type), SystemArticleRespVO.class));
    }

    @GetMapping("/get")
    @Operation(summary = "获得文章")
    @PermitAll
    public CommonResult<SystemArticleRespVO> getArticle(@RequestParam String title) {
        return success(BeanUtils.toBean(articleService.getArticleByTitle(title), SystemArticleRespVO.class));
    }


}